<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("Utf-8");%>
<jsp:useBean id="student" class="hb.software.student.entity.Student"></jsp:useBean>
<jsp:setProperty property="*" name="student"/>
<%
   try{
       Class.forName("com.mysql.jdbc.Driver");
       String url="jdbc:mysql://localhost:3306/studentmanagement";
       String username="root";
       String password="123456";
       Connection conn= DriverManager.getConnection(url,username,password);
       String sql="insert into t_student(name,age,address,score) value(????)";

       PreparedStatement ps=conn.prepareStatement(sql);
       ps.setString(1,student.getName());
       ps.setString(2,student.getAge());
       ps.setString(3,student.getAddress());
       ps.setString(4,student.getScore());
       int row=ps.executeUpdate();
       if(row>0){out.print("成功添加"+row+"数据");
    }
    ps.close();
    conn.close();

   }catch(Exception e){
       out.print("失败");
       e.printStackTrace();
   }
   %>
   <br>
   <a >href="main.jsp"返回 </a>
</body>
</html>
